var uuidV4 = require('uuid/v4');
var Eventproxy = require('eventproxy');
var logger = require('../common/logger');
var models = require('../models');
var tools = require('../common/tools');
var config = require('config-lite');
var Sequelize = require('sequelize');

exports.checkin = function checkin(req, res, next) {
  var data = req.body;
  logger.info(data);

  var ep = new Eventproxy();
  ep.fail(next);

  ep.all('missing', function (attrs) {
    if (attrs.length) {
      return res.send_data({
        code: 400,
        message: '缺少字段' + attrs
      });
    }
  });
  var missingAttrs = tools.checkMissingAttr(data, ['area_uuid', 'user_uuid', 'time', 'staff_uuid']);
  if (missingAttrs.length) {
    return ep.emit('missing', missingAttrs);
  }

  var user = req.user;
  data.event_uuid = user.event_uuid;

  models.signlog.create(data).then(function() {
    return res.send_data();
  });
};
